// There should not be negative values in rawData
const rawData = [
  [100, 302, 301, 334, 390, 330, 320],
  [320, 132, 101, 134, 90, 230, 210],
  [220, 182, 191, 234, 290, 330, 310],
  [150, 212, 201, 154, 190, 330, 410],
  [820, 832, 901, 934, 1290, 1330, 1320]
]
const totalData = []
for (let i = 0; i < rawData[0].length; ++i) {
  let sum = 0
  for (let j = 0; j < rawData.length; ++j) {
    sum += rawData[j][i]
  }
  totalData.push(sum)
}
const series = [
  'Direct',
  'Mail Ad',
  'Affiliate Ad',
  'Video Ad',
  'Search Engine'
].map((name, sid) => {
  return {
    name,
    type: 'bar',
    stack: 'total',
    barWidth: '60%',
    label: {
      show: true,
      formatter: (params) => Math.round(params.value * 1000) / 10 + '%'
    },
    data: rawData[sid].map((d, did) =>
      totalData[did] <= 0 ? 0 : d / totalData[did]
    )
  }
})
export const Event1 = {
  title: {
    text: 'Event详情',
    left: 'center',
    top: '10px',
    textStyle: {
      color: '#6C6C6C',
      fontSize: 16,
      fontWeight: 600,
      align: 'center'
    }
  },
  legend: {
    show: false,
    selectedMode: false
  },
  tooltip: {
    trigger: 'item',
    backgroundColor: 'rgba(69, 14, 255,0.5)',
    //   axisPointer: {
    //     type: 'cross' // 十字准线指示器，可选为：'line' | 'shadow'
    //   },
    borderWidth: '0',
    textStyle: {
      color: '#6DFFFF'
    },
    lineStyle: {
      width: 2,
      type: 'dashed' // 设置虚线类型
    },
    axisPointer: {
      // 坐标轴指示器，坐标轴触发有效
      type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
    },
    formatter: (params) => {
      return params.seriesName
    }
  },
  grid:
    {
      top: '15%',
      width: '91%',
      bottom: '3%',
      left: '5%',
      containLabel: true
    },
  yAxis: {
    type: 'value',
    show: false,
    axisLabel: {
      formatter: '',
      lineStyle: {
        color: '#090909'
      }
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#090909'
      }
    }
  },
  xAxis: {
    name: 'TDNo',
    type: 'category',
    axisLabel: {
      formatter: '{value}',
      lineStyle: {
        color: '#090909'
      }
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#090909'
      }
    },
    data: []
  },
  series
}

export const Event2 = {
  title: {
    // text: 'Event数量',
    left: 'center',
    top: '10px',
    textStyle: {
      color: '#6C6C6C',
      fontSize: 16,
      fontWeight: 600,
      align: 'center'
    }
  },
  legend: {
    show: false,
    selectedMode: false
  },
  grid:
    {
      top: '15%',
      width: '90%',
      bottom: '3%',
      left: '5%',
      containLabel: true
    },
  yAxis: {
    type: 'value',
    show: false,
    axisLabel: {
      formatter: '',
      lineStyle: {
        color: '#090909'
      }
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#090909'
      }
    }
  },
  xAxis: {
    name: 'TDNo',
    type: 'category',
    axisLabel: {
      formatter: '{value}',
      lineStyle: {
        color: '#090909'
      }
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#090909'
      }
    },
    data: []
  },
  series
}
